module.exports = app => {
  const mongoose = app.mongoose,
        Schema = mongoose.Schema;
  /**
   * @ Dict data schema
   */
  let DictSchema = new Schema({
    name: String,
    type: String,
    status: { type: Number, default: 1 },
    date: { type: Number, default: Date.now }
  });
  DictSchema.statics = {
    add(data) {
      return data.save();
    },
    update(id, data) {
      return this.findByIdAndUpdate({_id: id}, {$set: data}, {new: true});
    },
    findAll(params, cb) {
      const p = params.page - 1,
            s = params.size - 0;
      return this.find()
                .sort({'date': -1})
                .limit(s)
                .skip(p * s)
                .exec(cb);
    },
    del(id) {
      return this.remove({_id: id}).exec();
    }
  };
  return mongoose.model('Dict', DictSchema);
}